package com.arron.state.study1;

public class RestrictedState extends AccountState{
    public RestrictedState(AccountState state) {
        this.acc = state.acc;
    }

    @Override
    void deposit(double amount) {
        this.acc.setBalance(this.acc.getBalance()+amount);
        this.stateCheck();
    }

    @Override
    void withdraw(double amount) {
        this.acc.setBalance(this.acc.getBalance()-amount);
        this.stateCheck();
    }

    @Override
    void computerInterest() {
        System.out.println("受限状态，支付利息！");
    }

    @Override
    void stateCheck() {
        if(this.acc.getBalance()>=-2000&&this.acc.getBalance()<0){
            this.acc.setState(new OverDraftState(this));
        }
        else if(this.acc.getBalance()>=0){
            this.acc.setState(new NormalState(this));
        }
    }
}
